#include <iostream>

class RangeIterator 
{
	friend std::ostream &operator <<(std::ostream &os, const RangeIterator &range);
public:
	RangeIterator(int current, int step) : current(current), step(step) {}
	int &operator *() {return current;}
	RangeIterator operator ++();
	bool operator ==(const RangeIterator &other) {return current == other.current && step == other.step;} 
	bool operator !=(const RangeIterator &other) {return !(*this == other);}
private:
	int current, step;
};

class Range 
{
	friend std::ostream &operator <<(std::ostream &os, const Range &range);
public:
	Range(int first, int last, int step=1) : first(first), last(last), step(step) {}
	Range(int last) : first(1), last(last), step(1) {}

	RangeIterator begin() {return RangeIterator(first, step);}
	RangeIterator end() {return RangeIterator(last+(step-(last-first)%step), step);}
private:
	int first, last, step;
};
